<template>
    <div>
        <span v-if="isApply">
          <span class="seachStatus">
              {{$t('tsktpy')}}
              <el-select v-model="taskType" :placeholder="$t('plsset')" size="mini">
                  <el-option v-if="apply1" :label="$t('merarcaud')" :value="0"></el-option>
                  <el-option v-if="apply2" :label="$t('freunmer')" :value="1"></el-option>
                  <el-option v-if="apply3" :label="$t('payaud')" :value="2"></el-option>
              </el-select>
          </span>
          <el-button type="primary" size="mini" @click="seachTask" class="queryTask">{{$t('qury')}}</el-button>
          <el-card class="cardBox">
            <el-table border style="width: 100%" :data="taskDataTab">
                <el-table-column prop="type" :label="$t('tsktpy')">
                </el-table-column>
                <el-table-column prop="num" :label="$t('numoftasks')">
                </el-table-column>
                <el-table-column prop="address" :label="$t('opratn')" width="150" fixed="right">
                    <template slot-scope="scope">
                        <el-link type="primary" :disabled="scope.row.isAble" @click="seeTask(scope.row.type)">{{$t('see')}}</el-link>
                    </template>
                </el-table-column>
            </el-table>
          </el-card>
        </span>
    </div>
</template>

<script>
import {
  getuserinfofunlist,
  merlist,
  getauditsettlepaymentList
} from '@/libs/reqlist.js'
import Cookies from 'js-cookie'
export default {
    data () {
        return {
          taskType: 0,
          taskDataItem: {
            type: '',
            num: 0
          },
          asdList: [],
          taskDataTab: [],
          seachTaskForm: {
            orderNo: null,
            auditStatus: 'WAITCONFIRM',
            name: null,
            startTime: null,
            endTime: null,
            merId: null,
            orderParamIdx: 0,
            orderType: null,
            applyTypeList: [],
            pageNum: 1,
            pageSize: 10
          },
          isApply: false,
          apply1: false,
          apply2: false,
          apply3: false
        }
    },
    methods: {
      initSeach () {
        if (window.sessionStorage.getItem('activePath')) this.activePath = window.sessionStorage.getItem('activePath')
        getuserinfofunlist().then(res => {
          if (res.data.code === '000000') {
            let ownArr = []
            for (let i = 0; i <= res.data.data.length - 1; i++) {
              let jay = res.data.data[i]
              if (jay.flag === true) {
                let mychild = []
                for (let x = 0; x <= jay.children.length - 1; x++) {
                  let damnshine = jay.children[x]
                  if (damnshine.flag === true) {
                    mychild.push(damnshine)
                  }
                }
                jay.children = mychild
                ownArr.push(jay)
              }
            }
            this.asdList = ownArr
            for (let n = 0; n < this.asdList.length; n++) {
              let no = this.asdList[n]
              if (no.funcName === this.$t('audtskmag')) {
                this.isApply = true
                for (let x = 0; x < no.children.length; x++) {
                  let key = no.children[x]
                  if (key.funcName === this.$t('merarcaud')) this.apply1 = true
                  if (key.funcName === this.$t('freunmer')) this.apply2 = true
                  if (key.funcName === this.$t('payaud')) this.apply3 = true
                }
              }
            }
            if (this.isApply) {
              this.seachTask()
            }
          }
        })
      },
      seachTask () {
        this.seachTaskForm.applyTypeList = []
        this.taskDataTab = []
        if (this.taskType === 0) {
          this.seachTaskForm.applyTypeList.push('MER_REG')
          merlist(JSON.stringify(this.seachTaskForm)).then(res => {
            if (res.data.code === '000000') {
              this.taskDataItem.type = this.$t('merarcaud')
              this.taskDataItem.num = res.data.data.total - 0
              this.taskDataTab.push(this.taskDataItem)
            }
          })
        }
        if (this.taskType === 1) {
          this.seachTaskForm.applyTypeList.push('MER_FROZEN')
          this.seachTaskForm.applyTypeList.push('MER_UNFROZEN')
          merlist(JSON.stringify(this.seachTaskForm)).then(res => {
            if (res.data.code === '000000') {
              this.taskDataItem.type = this.$t('freunmer')
              this.taskDataItem.num = res.data.data.total - 0
              this.taskDataTab.push(this.taskDataItem)
            }
          })
        }
        if (this.taskType === 2) {
          this.seachTaskForm.applyTypeList.push('SUBMIT_SETTLE_PAY')
          getauditsettlepaymentList(JSON.stringify(this.seachTaskForm)).then(res => {
            if (res.data.code === '000000') {
              this.taskDataItem.type = this.$t('payaud')
              this.taskDataItem.num = res.data.data.total - 0
              this.taskDataTab.push(this.taskDataItem)
            }
          })
        }
      },
      seeTask (type) {
        if (type === this.$t('merarcaud')) {
          this.$router.push('/merApplyOrder/merAud')
        }
        if (type === this.$t('freunmer')) {
          this.$router.push('/ramAccAud')
        }
        if (type === this.$t('payaud')) {
          this.$router.push('/moneyAudit')
        }
      }
    },
    async mounted () {
      this.initSeach()
    }
}
</script>

<style lang="less" scoped>
@import './home.less';
</style>
